package com.running.mobile;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
import com.isomorphic.datasource.DataSource;
import com.isomorphic.datasource.DataSourceManager;

/**
 * 客户分类操作
 * @author Administrator
 *
 */
public class CustomerCategoryDMI {
	/**
	 * 删除时验证分类是否被客户表使用，如果被使用，不能删除
	 * @param session
	 * @param request
	 * @param rep
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Map remove(HttpSession session,DSRequest request ,DSResponse rep ,Map record)throws Exception
	{
		//验证该分类是否被使用
		DataSource cusds = DataSourceManager.getDataSource("customerDS");
		Map map = new HashMap();
		Map user = (Map) session.getAttribute("currUser");
		map.put("corp_sid", user.get("corp_sid"));
		map.put("user_pk", user.get("pk"));
		map.put("category_pk",record.get("pk"));
		
		if(cusds.hasRecord(map)){
			//已经被使用
			throw new RuntimeException("该分类已经被使用，禁止删除");
		}else{
			request.execute();
		}
		return record;
	}

}
